define(function (require, exports, module) {
    require("apps/grid");
    exports.init = function(ctx, uuid){
        var _pageComponent = new $.PageDomFactory(uuid);
        var pageListComponent = new $.PageListComponent(uuid, {
            view: {
                grid: "grid",
                myToolbar: "news_tb",
                colbar: "user_list_btn"
            },
            configs: {
                gridTitle: "模板列表",
                gridUrl: ctx + "/app/api/process/findProcessTemplate",
                idField:"id",
                gridColumns: [
                    {
                        field: 'id',
                        checkbox: true
                    },
                    {
                        field: 'temp1',
                        hidden: true
                    },
                    {
                        field: 'processName',
                        title: '模板名称',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'module.dirValue',
                        title: '模板类别',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'processCover',
                        title: '封面',
                        width: 50,
                        align: 'left',
                        formatter: function (value, row, index) {
                            var v = ctx + "/print/upload/default/pic2.png";
                            if (value) {
                                v = ctx + "/print/" + value;
                            }
                            return '<img data-id="userHead" src="' + v + '" style="width: 36px;height: 36px;" >';
                        }
                    },
                    {
                        field: 'createUser',
                        title: '创建人',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'useAble',
                        title: '是否启用',
                        width: 50,
                        align: 'left',
                        formatter: function (value, row, index) {
                            if (value == "1"
                                && value != null) {
                                return "启用";
                            } else {
                                return "禁用";
                            }
                        }
                    },
                    {
                        field: 'useDevice',
                        title: '使用设备',
                        width: 50,
                        align: 'left',
                        formatter: function (value, row, index) {
                            if (value == "1"
                                && value != null) {
                                return "使用";
                            } else {
                                return "未使用";
                            }
                        }
                    },
                    {
                        field: 'device.deviceName',
                        title: '设备名称',
                        width: 100,
                        align: 'left',
                        hidden: true
                    },
                    {
                        field: 'remark',
                        title: '备注',
                        width: 50,
                        align: 'left',
                        hidden: true
                    }
                ]
            },
            events: {
                renderColBarBefore: function (key, row) {
                    return true;
                },
                onClickColBtn: function (context, btn, row) {
                    switch (btn.key) {
                        case "preview":
                            whenPreview(context, btn.href, row);
                            break;
                        case "view":
                            whenView(context, row);
                            break;
                        default :
                            break;
                    }
                },
                onClickToolbarBtn: function (context, btn) {
                    switch (btn.key) {
                        case "search_all":
                            context.searchAll();
                            break;
                        case "search":
                            context.search(btn.href, "模板搜索", "process_search");
                            break;
                        default :
                            break;
                    }
                }
            }
        });

        var globalWindow = new $.PageWindow();

        function whenPreview(context, href, row) {
            globalWindow.create({
                width:800,
                href: href,
                title: "工艺模板预览"
            });
            globalWindow.open();
        }

        function whenView(context, row) {
            context.detail("工艺模板查看", row);
        }
    }
});